package com.isccp.efi.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.isccp.efi.dto.B013;
import com.isccp.efi.dto.TDpcaEfi078;
import com.isccp.efi.service.TDpcaEfi078Service;
import com.isccp.efi.mapper.TDpcaEfi078Mapper;
import com.isccp.efi.util.GetDataUtil;
import com.isccp.efi.util.GetWsDataUtil;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author songyong
 * @description 针对表【t_dpca_efi078】的数据库操作Service实现
 * @createDate 2024-02-04 14:38:13
 */
@Service
public class TDpcaEfi078ServiceImpl extends ServiceImpl<TDpcaEfi078Mapper, TDpcaEfi078>
        implements TDpcaEfi078Service {

    @Resource
    private GetWsDataUtil getWsDataUtil;
    @Override
    @Transactional
    public void syncData(String vendor) {

        List<TDpcaEfi078> res = getWsDataUtil.getYhl(vendor);

        List<TDpcaEfi078> list = new ArrayList<>();

        StringBuilder ids = new StringBuilder();

        for (TDpcaEfi078 efi078 : res) {
            QueryWrapper queryWrapper = new QueryWrapper<B013>().eq("ORDERNO", efi078.getORDERNO()).eq("VENDOR", efi078.getVENDOR());
            //数据不存在则新增保存
            if (baseMapper.selectCount(queryWrapper) == 0 && ("未阅".equals(efi078.getSTATE()) || "已阅".equals(efi078.getSTATE()))) {
                efi078.setINSERTTIME(new Date());
                efi078.setPRNSTATE(null);
                efi078.setSTATE("1");
                list.add(efi078);
            }
            if(ids.length()>0){
                ids.append(",");
            }
            ids.append(efi078.getORDERNO());
        }
        if (ids.length() > 0) {
            getWsDataUtil.confirmYhl(vendor, ids.toString());
        }
        if (list.size() > 0) {
            saveBatch(list);
        }
    }
}




